<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.5/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.5/themes/icon.css">
		<script type="text/javascript" src="js/jquery-easyui-1.4.5/jquery.min.js"></script>
		<script type="text/javascript" src="js/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="js/jquery-easyui-1.4.5/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
		<link rel="stylesheet" type="text/css" href="css/block.css" />
		<link rel="stylesheet" type="text/css" href="css/title.css"/>
		
	</head>

	<body>
			<div id="top" class="top">
		    <div id="top1">
		    	<div id="logo"><a href="login.html"  target="_self"><img src="img/logoword.jpg"/></div>
		    	
		    </div>
		    <div id="top2"  class="container">
	            <section class="c1">
		            <nav class="cl">
					<a href="main.html" target="_self" data-hover="主页"><span>主页</span></a>
					<a href="addR.html" target="_self" data-hover="美食收录"><span>美食收录</span></a>
					<a href="block.html" target="_self" data-hover="交流圈子"><span>交流圈子</span></a>
					<a href="usermain.html" target="_self" data-hover="个人主页"><span>个人主页</span></a>
		            </nav>
	            </section>	
            </div>
		     <div id="top3"></div>
		</div>
		<div id="bag">
			<div class="topBar">
				<table border="0" cellspacing="0" cellpadding="0" align="middle" class="topTable">
					<tr align="middle">
						<td id="1" class="block">美食推荐</td>
						<td id="2" class="block">厨艺交流</td>
						<td id="3" class="block">饮食健康</td>
						<td id="4" class="block">日常分享</td>
					</tr>
				</table>
				<button id="serchbtn">全站搜索</button>
				<input type="text" name="serch" id="serch" value="请输入要搜索的内容"  onblur="a()" onfocus="b()" />
								
			</div>

			<div id="d0">

				<div id="right">
					<div id="title">

					</div>
					<div id="sort">
						&nbsp
						<a href="#" id="fabu">最新发布</a>&nbsp;&nbsp;&nbsp;
						<a href="#" id="zan">高赞热贴</a>
					</div>
					<div id="d1">

						<table id="dg"  style="width:970px; border:false;background: #fff;" border='0' cellspacing='0' cellpadding='0' " >
								<tr id="tr0">
									<th  width="370px">标题</th>
									<th width="50px">发帖人</th>
									<th width="50px">获赞</th>
									<th  width="200px">发帖时间</th>
								</tr>
							
						</table>
					</div>
				</div>
				<div id="left">
					<h2>关注列表</h2>
					<ul id="concern">

					</ul>
				</div>
			</div>
		</div>
	</body>
<script>
		//加载界面
		var bid=1;//板块id ,默认为1
		//读取cookie进行跳转
		var c=document.cookie;
		console.log(c);
		var arr=c.split(";");
		for(var i=0;i<arr.length;i++){
			var key=arr[i].split("=")[0];
			var val=arr[i].split("=")[1];
			if(key.trim()=="bid"){
				bid=val;
				if(bid==""||bid.trim().length==0){
					bid=1;
				}
			}
		}
		var sortway=1;//排序方式  默认为1  1代表按回复时间  2代表点赞量
		function a(){
			if (document.getElementById("serch").value=="") {
				document.getElementById("serch").value="请输入要搜索的内容";
			}
		}
		function b(){
				if (document.getElementById("serch").value=="请输入要搜索的内容"||$("#serch").val()=="搜索内容不能为空") {
				document.getElementById("serch").value="";//set
			}
		}
		//加载关注列表 
		function showconcern(){
			$("#concern").empty();
			$.ajax({
				type:"post",
				url:"user?method=getGuanzhus",
				dataType:"json",
				success:function(d){
					console.log(d);
					var dlist=d.list;
					console.log(dlist);
					for(var i=0;i<dlist.length;i++){
						var tuser=dlist[i].user;
					//	console.log(tuser);
						$("#concern").append("<li class='cuser' name="+tuser.uid+">"+tuser.nickname+"  </li>")
					}
					show();
					
				}
			});
		}
		//显示所有板块和主贴
		function show(){
			$.ajax({
				type:"post",
				url:"block?method=show",
				dataType:"json",
				data:{
					'bid':bid,
					'sortway':sortway
				},
				success:function(d){
					var bname=d.bname;
					var bpicture=d.bpicture;
					var bhot=d.bhot;
					var bdes=d.bdescribe;
					var tname=$("<h2>#"+bname+"</h2>");
					$("#title").append(tname);
					var timg=$("<img id='titleImg' />");
					timg.attr("src","img/"+bpicture);
					$("#title").append(timg);
					var ttext=$("<div id='text'></div>")
					ttext.append("<p>话题介绍:"+bdes+"</p>");
					ttext.append("<p>话题热度:"+bhot+"w</p>");
					$("#title").append(ttext);	
					$("#title").append("<button id='post'>发帖   </button>");		
					var tlist=d.mlist;
					for(var i=0;i<tlist.length;i++){
						var ttr=$("<tr class='mpost'></tr>");
						ttr.append("<td  width=\"370px\" class='mtitle'> <a href='#'>"+tlist[i].mtitle+"</a></th>");
						ttr.append("<td  width=\"50px\" name='"+tlist[i].mid+"'>"+tlist[i].muname+"</th>");
						ttr.append("<td  width=\"50px\">"+tlist[i].mcount+"</th>");
						ttr.append("<td  width=\"200px\">"+tlist[i].mdate+"</th>");
						$("#dg").append(ttr);
					}
				}
			});
		}
		//全局搜索
		function serchShow(){
			if($("#serch").val()==null||$("#serch").val()=="请输入要搜索的内容"||$("#serch").val()=="搜索内容不能为空"){
				$("#serch").val("搜索内容不能为空");
			}else{
				clear();
				$.ajax({type:"post",
					url:"block?method=serchShow",
					dataType:"json",
					data:{
						'bid':bid,
						'serch':$("#serch").val()
					},
					success:function(d){
						var tlist=d.obj;
						for(var i=0;i<tlist.length;i++){
							var ttr=$("<tr class='mpost'></tr>");
							ttr.append("<td  width=\"370px\" class='mtitle'> <a href='#'>"+tlist[i].mtitle+"</a></th>");
							ttr.append("<td  width=\"50px\" name='"+tlist[i].mid+"'>"+tlist[i].muname+"</th>");
							ttr.append("<td  width=\"50px\">"+tlist[i].mcount+"</th>");
							ttr.append("<td  width=\"200px\">"+tlist[i].mdate+"</th>");
							$("#dg").append(ttr);
						}
					}
					});
			}
		}
		//清空板块和   主贴信息
		function clear(){
			$("#dg tr").not(":eq(0)").empty();
			$("#title").empty();
		}
			$(function(){
				showconcern();
				
				$(".block").click(function(){
					bid=$(this).attr("id");
					sortway=1;
					console.log(bid);
					clear();
					show();
				});
				$("#fabu").click(function(){
					sortway=1;
					clear();
					show();
				});
				$("#zan").click(function(){
					sortway=2;
					clear();
					show();
				});
				$("#serchbtn").click(function(){
					serchShow();
				});
				$("#title").on('click','#post',function(){
					$.ajax({
						type:"post",
						url:"block?method=isyscore",
						success:function(d){
							console.log("success");
							if(d==0){
								location.href="lastsendpost.html";
							}else{
								alert("等级不足不能发帖");
							}
							
						}
					
				});
				});
				$("#dg").on('click','.mtitle',function(){
					//location.href="sendpost.html";
					//var mid= $(this).next().attr("name");
					console.log("click");
					$.ajax({
							type:"post",
							url:"block?method=toreply",
							data:{
								'mid':$(this).next().attr("name")
							},
							success:function(d){
								console.log("success");
								location.href="reply.html";
							}
						
					});
				});
			});
		</script>
</html>